home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / SASC_6.0_Disk_4.adf / Compiler_Headers / Include / utility / hooks.h < prev    next >
C/C++ Source or Header  |  1992-07-30  |  2KB  |  91 lines

  1. #ifndef UTILITY_HOOKS_H
  2. #define UTILITY_HOOKS_H TRUE
  3. /*
  4. **    $Filename: utility/hooks.h $
  5. **    $Release: 2.04 Includes, V37.4 $
  6. **    $Revision: 36.1 $
  7. **    $Date: 90/07/12 $
  8. **
  9. **    callback hooks
  10. **
  11. **    (C) Copyright 1989-1991 Commodore-Amiga Inc.
  12. **        All Rights Reserved
  13. */
  14.  
  15. #ifndef EXEC_TYPES_H
  16. #include "exec/types.h"
  17. #endif
  18.  
  19. #ifndef EXEC_NODES_H
  20. #include "exec/nodes.h"
  21. #endif
  22.  
  23. /* new standard hook structure */
  24. struct Hook    {
  25.     struct MinNode    h_MinNode;
  26.     ULONG        (*h_Entry)();    /* assembler entry point    */
  27.     ULONG        (*h_SubEntry)();/* often HLL entry point    */
  28.     VOID        *h_Data;    /* owner specific        */
  29. };
  30.  
  31. /*
  32.  * Hook calling conventions:
  33.  *    A0 - pointer to hook data structure itself
  34.  *    A1 - pointer to parameter structure ("message") typically
  35.  *         beginning with a longword command code, which makes
  36.  *         sense in the context in which the hook is being used.
  37.  *    A2 - Hook specific address data ("object," e.g, GadgetInfo)
  38.  *
  39.  * Control will be passed to the routine h_Entry.  For many
  40.  * High-Level Languages (HLL), this will be an assembly language
  41.  * stub which pushes registers on the stack, does other setup,
  42.  * and then calls the function at h_SubEntry.
  43.  *
  44.  * The C standard receiving code is:
  45.  * CDispatcher( hook, object, message )
  46.  *     struct Hook    *hook;
  47.  *     APTR        object;
  48.  *     APTR        message;
  49.  *
  50.  * NOTE that register natural order differs from this convention
  51.  * for C parameter order, which is A0,A2,A1.
  52.  *
  53.  * The assembly language stub for "vanilla" C parameter conventions
  54.  * could be:
  55.  
  56.  _hookEntry:
  57.     move.l    a1,-(sp)        ; push message packet pointer
  58.     move.l    a2,-(sp)        ; push object pointer
  59.     move.l    a0,-(sp)        ; push hook pointer
  60.     move.l    h_SubEntry(a0),a0    ; fetch C entry point ...
  61.     jsr    (a0)            ; ... and call it
  62.     lea    12(sp),sp        ; fix stack
  63.     rts
  64.  
  65.  * with this function as your interface stub, you can write
  66.  * a Hook setup function as:
  67.  
  68.  SetupHook( hook, c_function, userdata )
  69.  struct Hook    *hook;
  70.  ULONG        (*c_function)();
  71.  VOID        *userdata;
  72.  {
  73.     ULONG    (*hookEntry)();
  74.  
  75.     hook->h_Entry =        hookEntry;
  76.     hook->h_SubEntry =    c_function;
  77.     hook->h_Data =            userdata;
  78.  }
  79.  
  80.  * with Lattice C pragmas, you can put the C function in the
  81.  * h_Entry field directly if you declare the function:
  82.  
  83. ULONG __saveds __asm
  84. CDispatcher(    register __a0 struct Hook    *hook,
  85.         register __a2 VOID        *object,
  86.         register __a1 ULONG        *message );
  87.  *
  88.  ****/
  89.  
  90. #endif
  91.